package com.zdb.controller;

import com.zdb.common.Result;
import com.zdb.pojo.Categorie;
import com.zdb.service.CategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/categories")
public class CategoriesController {
    @Autowired
    private CategoriesService categoriesService;

    @GetMapping
    public Result list() {
       return Result.sucess("分类列表",categoriesService.list());
    }
    @GetMapping("/{id}")
    public Result get(@PathVariable("/id")Integer id) {
        return Result.sucess("分类列表",categoriesService.getById(id));
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("/id")Integer id) {
        return Result.sucess("删除成功",categoriesService.removeById(id));
    }

    @PostMapping("/")
    public Result add(@RequestBody Categorie categorie) {
        return Result.sucess("添加成功",categoriesService.add(categorie));
    }

    @PutMapping("/")
    public Result update(@RequestBody Categorie categorie) {
        return Result.sucess("更新成功",categoriesService.update(categorie));
    }
}

